package c.e.a.b.f.b;

import java.lang.Thread.UncaughtExceptionHandler;
import java.util.Objects;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicLong;

/* compiled from: com.google.android.gms:play-services-measurement-impl@@18.0.0 */
public final class r4 extends r5 {
    public static final AtomicLong k = new AtomicLong(Long.MIN_VALUE);
    public v4 c;
    public v4 d;
    public final PriorityBlockingQueue<s4<?>> e = new PriorityBlockingQueue();
    public final BlockingQueue<s4<?>> f = new LinkedBlockingQueue();
    public final UncaughtExceptionHandler g = new t4(this, "Thread death: Uncaught exception on worker thread");
    public final UncaughtExceptionHandler h = new t4(this, "Thread death: Uncaught exception on network thread");
    public final Object i = new Object();
    public final Semaphore j = new Semaphore(2);

    public r4(u4 u4Var) {
        super(u4Var);
    }

    public final void f() {
        if (Thread.currentThread() != this.d) {
            throw new IllegalStateException("Call expected from network thread");
        }
    }

    public final void g() {
        if (Thread.currentThread() != this.c) {
            throw new IllegalStateException("Call expected from worker thread");
        }
    }

    public final boolean r() {
        return false;
    }

    /* JADX WARNING: Missing exception handler attribute for start block: B:15:0x002f */
    /* JADX WARNING: Can't wrap try/catch for region: R(6:15|16|(1:18)(1:19)|20|21|22) */
    /* JADX WARNING: Missing block: B:7:0x000c, code skipped:
            r2 = r2.get();
     */
    /* JADX WARNING: Missing block: B:8:0x0010, code skipped:
            if (r2 != null) goto L_0x002e;
     */
    /* JADX WARNING: Missing block: B:9:0x0012, code skipped:
            r3 = d().i;
            r4 = "Timed out waiting for ";
     */
    /* JADX WARNING: Missing block: B:10:0x001e, code skipped:
            if (r5.length() == 0) goto L_0x0025;
     */
    /* JADX WARNING: Missing block: B:11:0x0020, code skipped:
            r4 = r4.concat(r5);
     */
    /* JADX WARNING: Missing block: B:12:0x0025, code skipped:
            r4 = new java.lang.String(r4);
     */
    /* JADX WARNING: Missing block: B:13:0x002b, code skipped:
            r3.a(r4);
     */
    /* JADX WARNING: Missing block: B:14:0x002e, code skipped:
            return r2;
     */
    /* JADX WARNING: Missing block: B:16:?, code skipped:
            r3 = d().i;
            r4 = "Interrupted waiting for ";
     */
    /* JADX WARNING: Missing block: B:17:0x003b, code skipped:
            if (r5.length() != 0) goto L_0x003d;
     */
    /* JADX WARNING: Missing block: B:18:0x003d, code skipped:
            r4 = r4.concat(r5);
     */
    /* JADX WARNING: Missing block: B:19:0x0042, code skipped:
            r4 = new java.lang.String(r4);
     */
    /* JADX WARNING: Missing block: B:20:0x0048, code skipped:
            r3.a(r4);
     */
    /* JADX WARNING: Missing block: B:22:0x004d, code skipped:
            return null;
     */
    public final <T> T s(java.util.concurrent.atomic.AtomicReference<T> r2, long r3, java.lang.String r5, java.lang.Runnable r6) {
        /*
        r1 = this;
        monitor-enter(r2);
        r0 = r1.a();	 Catch:{ all -> 0x004e }
        r0.v(r6);	 Catch:{ all -> 0x004e }
        r2.wait(r3);	 Catch:{ InterruptedException -> 0x002f }
        monitor-exit(r2);	 Catch:{ all -> 0x004e }
        r2 = r2.get();
        if (r2 != 0) goto L_0x002e;
    L_0x0012:
        r3 = r1.d();
        r3 = r3.i;
        r4 = "Timed out waiting for ";
        r6 = r5.length();
        if (r6 == 0) goto L_0x0025;
    L_0x0020:
        r4 = r4.concat(r5);
        goto L_0x002b;
    L_0x0025:
        r5 = new java.lang.String;
        r5.<init>(r4);
        r4 = r5;
    L_0x002b:
        r3.a(r4);
    L_0x002e:
        return r2;
    L_0x002f:
        r3 = r1.d();	 Catch:{ all -> 0x004e }
        r3 = r3.i;	 Catch:{ all -> 0x004e }
        r4 = "Interrupted waiting for ";
        r6 = r5.length();	 Catch:{ all -> 0x004e }
        if (r6 == 0) goto L_0x0042;
    L_0x003d:
        r4 = r4.concat(r5);	 Catch:{ all -> 0x004e }
        goto L_0x0048;
    L_0x0042:
        r5 = new java.lang.String;	 Catch:{ all -> 0x004e }
        r5.<init>(r4);	 Catch:{ all -> 0x004e }
        r4 = r5;
    L_0x0048:
        r3.a(r4);	 Catch:{ all -> 0x004e }
        r3 = 0;
        monitor-exit(r2);	 Catch:{ all -> 0x004e }
        return r3;
    L_0x004e:
        r3 = move-exception;
        monitor-exit(r2);	 Catch:{ all -> 0x004e }
        throw r3;
        */
        throw new UnsupportedOperationException("Method not decompiled: c.e.a.b.f.b.r4.s(java.util.concurrent.atomic.AtomicReference, long, java.lang.String, java.lang.Runnable):java.lang.Object");
    }

    public final <V> Future<V> t(Callable<V> callable) throws IllegalStateException {
        o();
        s4 s4Var = new s4(this, (Callable) callable, false, "Task exception on worker thread");
        if (Thread.currentThread() == this.c) {
            if (!this.e.isEmpty()) {
                d().i.a("Callable skipped the worker queue.");
            }
            s4Var.run();
        } else {
            u(s4Var);
        }
        return s4Var;
    }

    public final void u(s4<?> s4Var) {
        synchronized (this.i) {
            this.e.add(s4Var);
            v4 v4Var = this.c;
            if (v4Var == null) {
                v4Var = new v4(this, "Measurement Worker", this.e);
                this.c = v4Var;
                v4Var.setUncaughtExceptionHandler(this.g);
                this.c.start();
            } else {
                synchronized (v4Var.a) {
                    v4Var.a.notifyAll();
                }
            }
        }
    }

    public final void v(Runnable runnable) throws IllegalStateException {
        o();
        Objects.requireNonNull(runnable, "null reference");
        u(new s4(this, runnable, false, "Task exception on worker thread"));
    }

    public final void w(Runnable runnable) throws IllegalStateException {
        o();
        u(new s4(this, runnable, true, "Task exception on worker thread"));
    }

    public final void x(Runnable runnable) throws IllegalStateException {
        o();
        s4 s4Var = new s4(this, runnable, false, "Task exception on network thread");
        synchronized (this.i) {
            this.f.add(s4Var);
            v4 v4Var = this.d;
            if (v4Var == null) {
                v4Var = new v4(this, "Measurement Network", this.f);
                this.d = v4Var;
                v4Var.setUncaughtExceptionHandler(this.h);
                this.d.start();
            } else {
                synchronized (v4Var.a) {
                    v4Var.a.notifyAll();
                }
            }
        }
    }

    public final boolean y() {
        return Thread.currentThread() == this.c;
    }
}
